Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: h264 level selection algorithm #1049

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RebootVanChild
Copy link

There seems to be a slight issue in the h264 level selection algorithm. Widths and heights of frames and h264 macroblocks should be taken into account when doing the calculation, not only the pixel counts.
This issue can cause encoder invalid param error on certain resolution ranges.

For example, a 1922x1080 30fps video stream:

The correct algorithm should be

macroblocksPerFrame = Ceil( pixelsFrameWidth / pixelsMacroblockSide ) * Ceil( pixelsFrameHeight / pixelsMacroblockSide )
= Ceil( 1922 / 16 ) * Ceil( 1080 / 16 )
= 8228

Which resides in level 4.2.

However, according to current algorithm

macroblocksPerFrame = Ceil( pixelsPerFrame / pixelsPerMacroblock )
= Ceil( 1922 * 1080 / (16 * 16) )
= 8109

Thus, the algorithm would select level 4, and cause encoder invalid param error.

@doctorpangloss
Copy link

is this related?

#896

Really the minimum level should always be h264 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants